package com.itheima.String.method;

import java.util.Scanner;

/**
 * @Author 王加鑫
 * @Date 2021/4/27 14:53
 * @Version 1.0
 * 模拟用户登录
 * 给三次机会老铁
 */
public class LoginTest {

    public static void main(String[] args) {
        //定义正确的账户和密码
        String username = "admin";
        String password = "123456";
        //初始次数
        int count = 1;
        while (count <= 3){
            //键盘录入环节
            Scanner sc = new Scanner(System.in);
            System.out.println("请输入账号:");
            String un = sc.nextLine();
            System.out.println("请输入密码:");
            String pw = sc.nextLine();
            if(password.equals(pw) && username.equals(un)){
                System.out.println("登录成功!!!");
                break;
            }else {
                if(count == 3){
                    System.out.println("登录失败,次数已用尽,请明天再来!!!");
                }else {
                    System.out.println("登录失败!!!还剩" + (3-count) + "次机会");
                }
            }
            count++;
        }
    }
}
